package br.com.obardavez.translator.impl;

import java.io.Serializable;
import java.util.Map.Entry;
import java.util.Set;

import br.com.obardavez.translator.Translator;
import br.com.obardavez.translator.properties.LabelProperties;
import br.com.obardavez.translator.properties.MessageProperties;

//@Singleton
public class TranslatorImpl implements Serializable, Translator {

	private static final long serialVersionUID = 1L;

	private static String DEFAULT_LANGUAGE = "pt_BR";

	private final LabelProperties labelProperties;

	private final MessageProperties messageProperties;

	public TranslatorImpl() {
		this.labelProperties = new LabelProperties();
		this.labelProperties.loadProperties(DEFAULT_LANGUAGE);
		this.messageProperties = new MessageProperties();
		this.messageProperties.loadProperties(DEFAULT_LANGUAGE);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.digicade.android.translator.impl.Translator#translateLabel(java.lang
	 * .String)
	 */
	@Override
	public String translateLabel(String key) {
		return this.labelProperties.getProperty(key);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.digicade.android.translator.impl.Translator#translateLabel(java.lang
	 * .String, java.lang.String)
	 */
	@Override
	public String translateLabel(String key, String... params) {
		return this.labelProperties.getProperty(key, params);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.digicade.android.translator.impl.Translator#translateMessage(java
	 * .lang.String)
	 */
	@Override
	public String translateMessage(String key) {
		return this.messageProperties.getProperty(key);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.digicade.android.translator.impl.Translator#translateMessage(java
	 * .lang.String, java.lang.String)
	 */
	@Override
	public String translateMessage(String key, String... params) {
		return this.messageProperties.getProperty(key, params);
	}

	/**
	 * Recupera todas as propriedades do arquivo de internacionalizacao de
	 * rotulos
	 * 
	 * @return Conjunto de properties contendo todos os rotulos
	 */
	@Override
	public Set<Entry<Object, Object>> getLabels() {
		return this.labelProperties.getProperties().entrySet();
	}

	/**
	 * Recupera todas as propriedades do arquivo de internacionalizacao de
	 * mensagens
	 * 
	 * @return Conjunto de properties contendo todas as mensagens
	 */
	@Override
	public Set<Entry<Object, Object>> getMessages() {
		return this.messageProperties.getProperties().entrySet();
	}

}
